import axios from 'axios';

const API_URL = 'http://localhost:3000/api/v1/chat/completions';
const API_KEY = 'fastgpt-S6y6vIHCao8oNkJlR59xxo9Klp7gnbyTnebDKheKGAdmUrQ0kfMvXk2';

const apiClient = axios.create({
  baseURL: API_URL,
  headers: {
    'Content-Type': 'application/json',
    'Authorization': `Bearer ${API_KEY}`
  }
});

/**
 * 发送消息并获取回复
 * @param {Array} conversationHistory 对话历史，包括用户和机器人的消息
 * @returns {Object} API响应数据
 */
export async function sendMessage(conversationHistory) {
  try {
    const response = await apiClient.post('', {
      model: 'gpt-3.5-turbo',
      messages: conversationHistory
    });
    return response.data; 
  } catch (error) {
    console.error('Error sending message:', error);
    throw error;
  }
}
